package heima3_2.cn.osc.hold;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import heima3_2.cn.osc.base.BaseHolder;
import heima3_2.cn.osc.base.MyBaseAdapter;
import heima3_2.cn.osc.constant.Constants;
import heima3_2.cn.osc.model.bean.BlogBean;
import heima3_2.cn.osc.ui.activity.ComprehensiveActivity;
import heima3_2.cn.osc.utils.Global;
import heima3_2.cn.osc.utils.PreferencesUtils;

/**
 * Created by Administrator on 2017/1/15 0015.
 */

public class SyntheRecommendHold extends BaseHolder<BlogBean> {
    @Bind(R.id.tv_title)
    TextView mTvTitle;
    @Bind(R.id.tv_body)
    TextView mTvBody;
    @Bind(R.id.tv_author)
    TextView mTvAuthor;
    @Bind(R.id.tv_pubdate)
    TextView mTvPubdate;
    @Bind(R.id.tv_commentcount)
    TextView mTvCommentcount;
    private BlogBean mBean;
    public SyntheRecommendHold(Context context, ViewGroup parent, MyBaseAdapter<BlogBean> adapter, int position, BlogBean bean) {
        super(context, parent, adapter, position, bean);
    }

    @Override
    public View onCreateView(final Context context, ViewGroup parent, int position, BlogBean bean) {
        this.mBean=bean;
        View inflats = Global.inflats(R.layout.lv_synthe_bogger_item);
        ButterKnife.bind(this,inflats);
        PreferencesUtils.setInt(context, Constants.RECOMMEND_ID,bean.id);
        final int ADVISORY_DETAILS=4;
        inflats.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(context, ComprehensiveActivity.class);
                intent.putExtra("ADVISORY_RECOMMEND",ADVISORY_DETAILS);
                Bundle bundle=new Bundle();
                bundle.putSerializable("RECOMMEND",mBean);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        return inflats;
    }

    @Override
    protected void onRefreshView(BlogBean bean, int position) {
        mTvTitle.setText(bean.title);
        mTvBody.setText(bean.body);
        mTvAuthor.setText(bean.author);
        mTvPubdate.setText(bean.pubDate);
        mTvCommentcount.setText(bean.commentCount+"");
    }
}
